package cn.stylefeng.guns.modular.manager.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.manager.entity.FlowMemberLog;
import cn.stylefeng.guns.modular.manager.mapper.FlowMemberLogMapper;
import cn.stylefeng.guns.modular.manager.model.params.FlowMemberLogParam;
import cn.stylefeng.guns.modular.manager.model.result.FlowMemberLogResult;
import  cn.stylefeng.guns.modular.manager.service.FlowMemberLogService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 会员物流地址 服务实现类
 * </p>
 *
 * @author yumker
 * @since 2021-01-14
 */
@Service
public class FlowMemberLogServiceImpl extends ServiceImpl<FlowMemberLogMapper, FlowMemberLog> implements FlowMemberLogService {

    @Override
    public void add(FlowMemberLogParam param){
        FlowMemberLog entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(FlowMemberLogParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(FlowMemberLogParam param){
        FlowMemberLog oldEntity = getOldEntity(param);
        FlowMemberLog newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public FlowMemberLogResult findBySpec(FlowMemberLogParam param){
        return null;
    }

    @Override
    public List<FlowMemberLogResult> findListBySpec(FlowMemberLogParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(FlowMemberLogParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(FlowMemberLogParam param){
        return param.getMemberLogId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private FlowMemberLog getOldEntity(FlowMemberLogParam param) {
        return this.getById(getKey(param));
    }

    private FlowMemberLog getEntity(FlowMemberLogParam param) {
        FlowMemberLog entity = new FlowMemberLog();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
